package tp4;

import java.util.Arrays;
import java.util.Iterator;

import tp4.iterators.ItCroissant;
import tp4.iterators.ItDecroissant;

public class TriBull extends TabContainer implements Trieur, Affichage {

	public TriBull() {

	}

	@Override
	public void trier(Integer[] tab) {
		this.tab = tab;
		sort(tab);
	}

	@Override
	public void afficher() {
		System.out.println(this);
	}

	public void sort(Integer[] tab) {

		boolean b = false;
		
		while (b == false) {
			b = true;
			for (Iterator<Integer> iterator = this.iterator(); iterator.hasNext();) {
				
				ItCroissant<Integer> it = (ItCroissant<Integer>) iterator;
				int cur= it.next();
				int na = it.nextAfter();
				boolean doTri = it.nextAfter() < it.current();
				if (doTri) {
					Integer aux = it.current();
					it.modify(it.nextAfter());
					it.modifyAfter(aux);
					b = false;
				}
			}
		}

	}
	@Override
	public Iterator<Integer> iterator() {
		return new ItCroissant<Integer>(tab);
		//return new ItDecroissant(this);
	}
}


//if (getTab()[i + 1] < getTab()[i]) {
//	Integer aux = getTab()[i];
//	getTab()[i] = getTab()[i + 1];
//	getTab()[i + 1] = aux;
//	b = false;
//}
